Component({
  options: {
    multipleSlots: true
  },
  properties: {
    title: { // 导航栏标题
      type: String,
      value: ''
    },
    titleSize: { // 导航栏标题字体大小
      type: [Number,String],
      value: 14
    },
    textStyle: { // 导航栏样式 white,black
      type: String,
      value: 'white'
    }, 
    bgColor: { // 导航和状态栏背景颜色
      type: String,
      value: 'none'
    },
    bgImg: { // 导航和状态栏背景图片
      type: String,
      value: ''
    },
    isDefault: { // 是否使用默认导航栏,false为自定义
      type: [String,Boolean],
      value: true
    },
    showHome:{ //是否需要显示home图标
      type: [Boolean,String],
      value: true
    }
  },
  data: {
    screenWidth: '', //屏幕宽度
    statusbar: '', //状态栏高度
    navbar: '', //导航栏高度
    level: '', //元素水平边距
    vertical: '', //元素垂直边距
    capWidth: '', //胶囊的宽度
    capHeight:'', //胶囊的高度
    system: 'android',//手机系统
    pageLength: 0, //页面栈长度
    bgBlack: `rgba(0, 0, 0, 0.32)`,
    bgWhite: `rgba(255, 255, 255, 0.84)`
  },
  lifetimes: {
    attached: function () {
      let _this = this;
      let page = getCurrentPages(); //获取页面栈
      _this.setData({
        pageLength: page.length
      })
      wx.getSystemInfo({
        success: e => {
          if (e.system.match("iOS")) {
            _this.setData({
              system: 'ios'
            })
          }
          let cap = wx.getMenuButtonBoundingClientRect();//获取胶囊信息
          let statusbar = e.statusBarHeight;
          let screenWidth = e.screenWidth;
          let navbar = cap.bottom + cap.top - 2*statusbar;  //导航栏高度
          let level = screenWidth - cap.right; //留白距离
          _this.setData({
            screenWidth: screenWidth,
            statusbar: statusbar,
            navbar: navbar,
            level: level,
            vertical: cap.top - statusbar,
            capWidth: cap.width,
            capHeight: cap.height
          })
        }
      })
    }
  },
  methods: {
    handleBack(){
      wx.navigateBack({
        delta: 1,
      })
    },
    handleHome(){
      wx.reLaunch({
        url: '/pages/index/index',
      })
    }
  }
})
